#include "apue.2e/include/apue.h"
// http://stackoverflow.com/questions/21558937/i-do-not-understand-how-execlp-work-in-linux
// http://www.albany.edu/~csi402/pdfs/handout_13.3.pdf
char* env_init[] = {"USER=unknown", "PATH=/tmp", NULL};

int main(void) {

	pid_t pid;
	int status; // child exit status

	if ( (pid = fork()) < 0) {
		printf("fork error \n");
		return 1;
	}

	if (pid == 0 ) { // child
		// if(execlp("ls","ls","-l",(char*)0)<0)
		// need gcc ex_echo_all.c -o ex_echo_all
		if (execlp("./ex_echo_all", "ex_echo_all", (char *)NULL, env_init) < 0)
			printf("execlp error\n");

		/* If the child process reaches this point, then */
		/* execlp must have failed. */
		fprintf(stderr, "Child process could not do execlp.\n");
		exit(1);
	} else { // parent
		wait(&status);
		printf("child process exit with status=%d\n", status);
	}
}
